using UnityEngine;

namespace Voodoo.Sauce.Internal.DebugScreen
{
	[RequireComponent(typeof(RectTransform))]
	public class SafeAreaRectTransform : MonoBehaviour
	{
		[SerializeField]
		private bool ignoreNotch;

		private RectTransform _rectTransform;

		private void Awake()
		{
			_rectTransform = base.transform as RectTransform;
		}

		private void Start()
		{
			ApplySafeArea();
		}

		private void ApplySafeArea()
		{
			Vector2 position = Screen.safeArea.position;
			Vector2 anchorMax = Screen.safeArea.position + Screen.safeArea.size;
			if (ignoreNotch)
			{
				anchorMax.y += (float)Screen.height - Screen.safeArea.max.y;
			}
			position.x /= Screen.width;
			position.y /= Screen.height;
			anchorMax.x /= Screen.width;
			anchorMax.y /= Screen.height;
			_rectTransform.anchorMin = position;
			_rectTransform.anchorMax = anchorMax;
		}
	}
}
